# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=gnu-cobol

pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-svn
pkgrel=1
pkgver=r275
pkgdesc="GNU Cobol is a free, modern COBOL compiler"
arch=('any')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url="http://sourceforge.net/projects/open-cobol/"
options=('strip')
license=('GPL' 'LGPL')
groups=("${MINGW_PACKAGE_PREFIX}")
makedepends=("subversion"
            "${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-libiconv")
depends=("${MINGW_PACKAGE_PREFIX}-db" 
        "${MINGW_PACKAGE_PREFIX}-gmp" 
        "${MINGW_PACKAGE_PREFIX}-ncurses")
source=("$_realname::svn+http://svn.code.sf.net/p/open-cobol/code/branches/gnu-cobol-2.0"
        fix-including-headers.patch)
md5sums=('SKIP'
         '6f8310009330fc0b5fba616cfab5c07b')

pkgver() {
  cd "$srcdir/$_realname"
  local ver="$(svnversion)"
  printf "r%s" "${ver//[[:alpha:]]}"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/fix-including-headers.patch
  autoreconf -fi
}

build() {
  export lt_cv_deplibs_check_method='pass_all' # libncurses
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../$_realname/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --infodir=${MINGW_PREFIX}/share/info \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static \
    --disable-rpath
  make
}

package() {
  cd ${srcdir}/build-${CARCH}
  make DESTDIR="$pkgdir" install
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname  
  cp -pf ${srcdir}/${_realname}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname
}
